<template>
  <div>
    <div class="m-dataList">
      <el-table
        :data="dataList"
        ref="dataList"
        v-loading="dataListLoading"
        element-loading-text="loading..."
        :max-height="800"
        style="width: 100%"
      >
        <el-table-column
          prop="customer_no"
          width="200"
          label="客户账号">
          <template slot-scope="scope">
            <a href="javascript:void(0)" @click="toInfo(scope.row.customer_no)">{{scope.row.customer_no}}</a>
          </template>
        </el-table-column>
        <el-table-column
          prop="open_customer_date"
          label="开户时间"
          :formatter="countTimeFormat"
          min-width="160">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  import * as LeadsAPI from '@/Api/lead';
  import * as Utils from '@/utils';
  import * as FollowUpAPI from '@/Api/followup';
  export default {
    name: 'TheAccount',
    data () {
      return {
        dataList: [],
        dataListLoading: false,
      }
    },
    props: ['type'],
    computed: {
      queryId(){
        return this.$route.params.id.split('_')[1]
      }
    },
    methods: {
      queryList(){
        this.dataListLoading = true;
        if (this.$refs.dataList) {
          this.$refs.dataList.bodyWrapper.scrollTop = 0;
        }
        LeadsAPI.leadInfo2_1({
          queryId: this.queryId,
        })
          .then(res => {
            this.dataListLoading = false;
            if (res.code != '0') {
              this.$notify.warning({
                title: '温馨提示',
                message: res.msg
              })
              return
            }
            this.dataList = res.data;
          })
          .catch(error => {
            this.dataListLoading = false;
            console.log(error)
          })
      },
      toInfo(id) {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
        });
        FollowUpAPI.followBelongInfo({
          type:'1',
          typeId:id,
        })
          .then(res=>{
            loading.close();
            if(res.code != '0') {
              this.$notify({
                title: '温馨提示',
                message: res.msg,
                type: 'warning'
              })
              return;
            }
            this.$router.push({
              name:'AccountDetailsInfo',
              params:{
                id:res.data.id+'_'+id+'_'+res.data.phone
              }
            })
          })
          .catch(error=>{
            loading.close();
            console.log(error);
          })
      },
      countTimeFormat(row, column){
        return Utils.countDateTimeFormat(row[column.property])
      },
    },
    created(){
      this.queryList();
    }
  }
</script>

<style scoped lang="scss">
</style>
